package com.geotmt.billingcenter.common.vo.params;

import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description 类描述
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/3/20 15:44
 * @Version     v1
 **/
public class PageOrgFilter {

    /**
     * 分页默认值设置
     * @param obj   参数
     * @param orderBy
     */
    public void filterPage(ParamsCost obj, String orderBy){
        if(null == obj.getPageNum()){
            obj.setPageNum(1);
        }
        if(null == obj.getPageSize()){
            obj.setPageSize(10);
        }
        if(StringUtils.isEmpty(obj.getOrderBy())){
            obj.setOrderBy(orderBy);
        }
    }

    /**
     * 分页默认值设置
     * @param obj
     * @param orderBy
     */
    public void filterPage(ParamsConsume obj, String orderBy){
        if(null == obj.getPageNum()){
            obj.setPageNum(1);
        }
        if(null == obj.getPageSize()){
            obj.setPageSize(10);
        }
        if(StringUtils.isEmpty(obj.getOrderBy())){
            obj.setOrderBy(orderBy);
        }
    }


    /**
     * 获取用户id
     * @param request
     * @return
     */
    public Integer getUserId(HttpServletRequest request){
        Integer userId = null;
        String uId = request.getAttribute("userId")+"";
        if(!StringUtils.isEmpty(uId)){
            userId = Integer.parseInt(uId);
        }
        return userId;
    }


}
